package com.taotao.controller;

import org.influxdb.InfluxDB;
import org.influxdb.dto.Point;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class TestController {
    @Autowired
    private InfluxDB influxDB;

    public void writeData() {
        Point point = Point.measurement("my_measurement")
                .tag("location", "Office")
                .addField("temperature", 23.5)
                .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
        influxDB.write(Point.measurement("my_measurement")
                .tag("location", "Office")
                .addField("temperature", 23.5)
                .build());
    }

    public void queryData() {
        Query query = new Query("SELECT * FROM my_measurement WHERE location='Office'", "my_database");
        QueryResult result = influxDB.query(query);
        // 处理查询结果
    }
}
